package vis.core.mapper;

import vis.core.domain.db.SysUser;
import com.mybatisflex.core.query.QueryWrapper;

import java.util.List;

import static vis.core.domain.db.table.SysUserTableDef.SYS_USER;

public interface SysUserMapper extends ZBMapper<SysUser> {

    default SysUser getOneByCode(String code) {
        QueryWrapper query = QueryWrapper.create()
                .and(SYS_USER.MT_CODE.eq(code));
        return selectOneByQuery(query);
    }

    default List<String> getIdLikeAnyFlag(String userNameOrPhone) {
        QueryWrapper query = QueryWrapper.create()
                .select("id")
                .and(SYS_USER.ID_CARD_NAME.like(userNameOrPhone))
                .and(SYS_USER.NICK_NAME.like(userNameOrPhone))
                .and(SYS_USER.ACCOUNT.like(userNameOrPhone))
                .and(SYS_USER.PHONE.like(userNameOrPhone));
        return selectObjectListByQueryAs(query, String.class);
    }

    default List<SysUser> getLikeAnyFlag(String userNameOrPhone) {
        QueryWrapper query = QueryWrapper.create()
                .and(SYS_USER.ID_CARD_NAME.like(userNameOrPhone))
                .and(SYS_USER.NICK_NAME.like(userNameOrPhone))
                .and(SYS_USER.ACCOUNT.like(userNameOrPhone))
                .and(SYS_USER.PHONE.like(userNameOrPhone));
        return selectListByQuery(query);
    }

    default String getNickName(String userId) {
        QueryWrapper query = QueryWrapper.create()
                .select("nick_name").eq("id", userId);
        return selectObjectByQueryAs(query, String.class);
    }
}